package com.wwx.validator;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;

import javax.validation.Validator;

/**
 * ValidationConfig
 *
 * @author 王伟欣
 * @version V1.0
 * @email w17731138318@126.com
 * @creator 2023-02-13 14:16
 * @company 晶品科技
 * @copyright 晶品科技 · 石家庄 · 技术二部
 */
@Configuration
public class ValidationConfig {

	@Bean
	public Validator getValidator() {
		ResourceBundleMessageSource bundleMessageSource = new ResourceBundleMessageSource();
		bundleMessageSource.setDefaultEncoding("UTF-8");
		bundleMessageSource.setBasenames("i18n/validation", "i18n/validation_common");
		LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
		validator.setValidationMessageSource(bundleMessageSource);
		return validator;
	}
}
